import { getParams, resolveParams } from "@/libs/util";
import Mock from "mockjs";

const USER_MAP = {
  super_admin: {
    name: "super_admin",
    user_id: "1",
    access: "super_admin",
    token: "super_admin"
  },
  admin: {
    name: "admin",
    user_id: "2",
    access: "admin",
    token: "admin"
  }
};

const login = Mock.mock(/\/login/, "post", function(req, res) {
  //let req = JSON.parse(req.body);
  //console.log(JSON.parse(req.body));
  req = resolveParams(req.body);
  return {
    code: 200,
    data: USER_MAP[req.userName],
    msg: ""
  };
});

const get_info = Mock.mock(/\/get_info/, "get", function(req, res) {
  const params = getParams(req.url);
  return {
    code: 200,
    data: USER_MAP[params.token],
    msg: ""
  };
});

const logout = Mock.mock(/\/logout/, "get", function(req, res) {
  return {
    code: 200,
    data: null,
    msg: ""
  };
});

export default { login, get_info, logout };
